<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="../base_top.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>购物车</title>
    
	<%@ include file="../base_head.jsp" %>    
	<link type="text/css" rel="stylesheet" href="<%=basePath%>css/user/style.css">
    <link type="text/css" rel="stylesheet" href="<%=basePath%>css/user/shopping_self.css">
    <link type="text/css" rel="stylesheet" href="<%=basePath%>css/user/well_style.css">
    <script type="text/javascript" src="<%=basePath%>js/user/shopcart.js"></script>
    <script type="text/javascript" src="<%=basePath%>js/jquery-1.4.3.min.js"></script>
    <script type="text/javascript" src="<%=basePath%>js/jquery.select.js"></script>
    <script type="text/javascript">
    //单项删除
   	$(".delete_one").live("click", function() {
    	var tr = $(this).parent().parent();
    	var id = tr.find("#cartId").val();
    	alert("delete: " + id);
    	$.ajax({
    		cache: false,
    		url:"shopcart/shopCartDel",
    		type: "GET",
    		data: {id: id, delType: "one"},
    		dataType:"json",
    	    success: function(data) {
    	    	if (data == "success") {
    	    		tr.remove();
    	    	}
    	    }
    	});
    });
    //删除选中
    $("#deleteAll").live("click", function() {
    	var box = $("input[name=check]:checked");
    	var url = "shopcart/shopCartDel?delType=all";
    	box.each(function() {
    		var tr = $(this).parent().parent();
    		var cartId = tr.find("#cartId").val();
    		url += "&cartIds=" + cartId;
    	});
    	var conf = confirm("确定删除吗？");
    	if (conf) {
	    	$.ajax({
	    		cache: false,
	    		url: url,
	    		type: "GET",
	    		data: {time:new Date()},
	    		dataType:"json",
	    	    success: function(data) {
	    	    	if (data == "success") {
	    	    		box.each(function() {
	    	    			$(this).parent().parent().remove();
	    	    		});
	    	    	}
	    	    }
	    	});
    	}
    });
    	
    // 检测重复
   	function checkArrayRepeat(array){
   		var hash={};
   		for(var i in array){
   			if(hash[array[i]]){
   				return true;
   			}
   			hash[array[i]]=true;
   		}
   		return false;
   	}
    
    // 检测存在不同值
    function checkArraySame(array) {
    	if (array.length != 0) {
	    	for (var i = 0; i<array.length; i++) {
	    		if (array[0] != array[i]) {
	    			return false;
	    		}
	    	}
	    	return true;
    	} else {
    		return true;
    	}
    }
    //清除下柜商品
    $("#removeAll").live("click", function() {
    	var box = $("input[name=check]");
    	var url = "shopcart/removeUnsellGoods";
    	var i = 0;
    	box.each(function() {
    		if (i == 0) {
    			url += "?cartIds=" + $(this).val();
    			i++;
    		} else {
    			url += "&cartIds=" + $(this).val();
    		}
    	});
    	$.ajax({
    		cache: false,
    		url: url,
    		type: "GET",
    		data: {time:new Date()},
    		dataType:"json",
    	    success: function(data) {
				if (data.length != 0) {
					box.each(function() {
						var id = $(this).val();
						if (jQuery.inArray(id, data) != -1) {
							$(this).parent().parent().remove();
						}
					});
				}
    	    }
    	});
    });
    
    
    // 结算
    function checkIterm() {
    	var box = $("input[name=check]:checked");
    	var length = box.length;
    	var array = new Array();
    	alert(length);
    	
    	for (var i = 0; i < length; i++) {
    		var tr = box[i].parent().parent();
    		var keeperId = tr.find("#keeperId").val();
    		array[i] = keeperId;
    	}
    	
    	if (length != 0) {
	    	if (checkArraySame(array)) {
	    		// 店铺相同，提交数据
	    		/*
	    		* 数据：
	    		* 1.购物车id
	    		* 2.商品编号
	    		*/
	    		var url = "";
	    		window.location.href
	    	} else { //发出警告
	    		alert("请将不同店铺的商品分开结算");
	    	}
    	}
    }
    </script>
  </head>
  <body>
<!--topbar开始-->
<%@ include file="../page_topbar.html" %>
<!--topbar结束-->
<div id="shopping_wrap">
    <!--search开始-->
    <div class="logo_w" id="common_logo_w">
        <img alt="" src="images/logo.png"/>
        <div class="search_all" id="common_search_all">
            <div class="search">
                <form name="searchform" method="post" action="">
                    <div class="select_box">
                        <div class="select_showbox" style="cursor: pointer;">搜索全部</div>
                        <ul class="select_option">
                            <li class="selected">搜索全部</li>
                            <li>新闻中心</li>
                            <li>技术文档</li>
                            <li>下载中心</li>
                        </ul>
                    </div>
                    <select name="classid" id="choose">
                        <option value="0">搜索全部</option>
                        <option value="1">新闻中心</option>
                        <option value="4">技术文档</option>
                        <option value="22">下载中心</option>
                    </select>
                    <input class="inp_srh" name="keyboard" placeholder="请输入商品关键字">
                    <input class="btn_srh" type="submit" name="submit" value="商品搜索"></form>
            </div>
        </div>
    </div>
    <!--search结束-->
    <!--标题开始-->
    <div class="shopping_title_all">全部商品</div>
    <!--标题结束-->
    <!--商品详情开始-->
    <table id="cartTable">
        <thead>
        <tr>
            <th><label><input class="check-all check" type="checkbox"/>&nbsp;全选</label></th>
            <th>商品</th>
            <th>单价(元)</th>
            <th>数量</th>
            <th>小计(元)</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <s:iterator value="#request['shopCarts']" id="cart">
        <tr>
        	<input type="hidden" id="cartId" value='<s:property value="#request.cart.cartId"/>'/>
        	<input type="hidden" id="keeperId" value='<s:property value="#request.cart.shopkeeperNum"/>'/>
            <td class="checkbox"><input class="check-one check" name="check" type="checkbox" value='<s:property value="#request.cart.cartId"/>'/></td>
            <td class="goods"><div class="addetail_title_con"><font><s:property value="#request.cart.skName"/></font></div><img src='<s:property value="#request.cart.gaPath"/>' alt=""/><span><s:property value="#request.cart.goodsName"/></span></td>
            <td class="price"><s:property value="#request.cart.goodsPrice"/></td>
            <td class="count">
                <span class="reduce"></span>
                <input class="count-input" type="text" value='<s:property value="#request.cart.cartNum"/>'/>
                <span class="add">+</span></td>
            <td class="subtotal"><s:property value="#request.cart.goodsPrice"/></td>
            <td class="operation"><span class="delete delete_one">删除</span></td>
        </tr>
        </s:iterator>
        <!-- <tr>
            <td class="checkbox"><input class="check-one check" type="checkbox"/></td>
            <td class="goods"><div class="addetail_title_con"><font>天猫专卖店</font></div><img src="images/1.jpg" alt=""/><span>Casio/卡西欧 EX-TR350</span></td>
            <td class="price">5999.88</td>
            <td class="count">
                <span class="reduce"></span>
                <input class="count-input" type="text" value="1"/>
                <span class="add">+</span></td>
            <td class="subtotal">5999.88</td>
            <td class="operation"><span class="delete">删除</span></td>
        </tr>
        <tr>
            <td class="checkbox"><input class="check-one check" type="checkbox"/></td>
            <td class="goods"><div class="addetail_title_con"><font>天猫专卖店</font></div><img src="images/1.jpg" alt=""/><span>Casio/卡西欧 EX-TR350</span></td>
            <td class="price">5999.88</td>
            <td class="count">
                <span class="reduce"></span>
                <input class="count-input" type="text" value="1"/>
                <span class="add">+</span></td>
            <td class="subtotal">5999.88</td>
            <td class="operation"><span class="delete">删除</span></td>
        </tr> -->
        </tbody>
    </table>

    <div class="foot" id="foot">
        <label class="fl select-all"><input type="checkbox" class="check-all check"/>&nbsp;全选</label>
        <a class="fl delete" id="deleteAll">删除选中的商品</a>
        <a class="fl delete" href="javascript:;" style="margin-left: 15px;">移到我的关注</a>
        <a class="fl delete" id="removeAll" style="margin-left: 15px;">清除下柜商品</a>
        <div class="fr closing" onclick="checkIterm();">结 算</div>
        <div class="fr total">合计：￥<span id="priceTotal">0.00</span></div>
        <div class="fr selected" id="selected">已选商品
            <span id="selectedTotal">0</span>件
            <span class="arrow up">︽</span>
            <span class="arrow down">︾</span>
        </div>
        <div class="selected-view">
            <div id="selectedViewList" class="clearfix">
                <!--<div><img src="images/1.jpg"><span>取消选择</span></div>-->
            </div>
            <span class="arrow">◆<span>◆</span></span>
        </div>
    </div>
    <!--商品详情结束-->
    
    <!-- 表单开始 -->
    
    <!-- 表单结束 -->
    
    <!--猜你喜欢开始-->
    <div id="tab_notice" class="tab_notice">
        <div id="tab_notice-tit" class="tab_notice-tit">
            <ul>
                <li class="tab_select">猜你喜欢</li>
                <li>我的关注</li>
                <li>最近浏览</li>
            </ul>
        </div>
        <div id="tab_notice-con" class="tab_notice-con">
            <div class="tab_mod" style="display:block">
                <ul>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="tab_mod" style="display:none">
                <ul>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="tab_mod" style="display:none">
                <ul>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                    <li>
                        <div class="other_ad_main">
                            <div class="other_ad_mainad">
                                <div class="img">
                                    <img src="images/img_05.jpg">
                                </div>
                                <div class="content">购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了购买该商品的用户还购买了</div>
                                <div class="price">￥8.00</div>
                                <div class="add">
                                    <input type="button" value="加入购物车">
                                </div>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!--猜你喜欢结束-->

</div>
</body>
</html>
